// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router/index'
import store from './store/'
import './config/rem'
import FastClick from 'fastclick'
import 'mint-ui/lib/style.css'
import $ from 'jquery'
import axios from './axios/axios';
import '../static/css/font_3t486sf5h650cnmi/iconfont.css';
import vueQuillEditor from 'vue-quill-editor'
import { InfiniteScroll } from 'mint-ui';
import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'babel-polyfill';
Vue.use(VueAwesomeSwiper)
Vue.use(InfiniteScroll);
// Vue.use(VueQuillEditor)

// 将axios挂载到prototype上，在组件中可以直接使用this.axios访问
Vue.prototype.axios = axios;


Vue.config.productionTip = false

Vue.filter('time', function (value) {//value为13位的时间戳
  function add0(m) {
    return m < 10 ? '0' + m : m
  }
  var time = new Date(parseInt(value));
  var y = time.getFullYear();
  var m = time.getMonth() + 1;
  var d = time.getDate();
  var H = time.getHours();
  var M = time.getMinutes();
  var S = time.getMilliseconds()

  return y + '-' + add0(m) + '-' + add0(d) + ' ' + add0(H) + ':' + add0(M) + ':' + add0(S);
});

if ('addEventListener' in document) {
  document.addEventListener('DOMContentLoaded', function() {
    FastClick.attach(document.body);
  }, false);
}

/* eslint-disable no-new */
new Vue({
  router,
  store,
}).$mount('#app')

var app = {
  // Application Constructor
  initialize: function() {
    document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
  },

  // deviceready Event Handler
  //
  // Bind any cordova events here. Common events are:
  // 'pause', 'resume', etc.
  onDeviceReady: function() {
    // this.receivedEvent('deviceready');
    document.addEventListener("backbutton", eventBackButton, false); //返回键
    router.start(App, 'app');
    window.navigator.splashscreen.hide();
  },

  //返回键
  eventBackButton(){
    //confirm("再点击一次退出!");
    window.plugins.ToastPlugin.show_short('再点击一次退出!');
    document.removeEventListener("backbutton", eventBackButton, false); //注销返回键
    //3秒后重新注册
    var intervalID = window.setInterval(
      function() {
        window.clearInterval(intervalID);
        document.addEventListener("backbutton", eventBackButton, false); //返回键
      },
      3000
    );
  },

// Update DOM on a Received Event
  receivedEvent: function(id) {
    var parentElement = document.getElementById(id);
    var listeningElement = parentElement.querySelector('.listening');
    var receivedElement = parentElement.querySelector('.received');

    listeningElement.setAttribute('style', 'display:none;');
    receivedElement.setAttribute('style', 'display:block;');

  },
};

app.initialize();


